package com.dao;

import com.Util.MybatisUtils;
import com.po.Vet;
import com.po.Vet_specialityKey;
import org.apache.ibatis.session.SqlSession;
import java.util.List;



public class VetDao {
/*  添加医生信息
    医生表*/
    public void addVet(Vet vet) throws Exception{
        SqlSession sqlSession = MybatisUtils.getSession();
        sqlSession.insert("com.mapper"
                + ".VetMapper.addVet", vet);
        sqlSession.commit();

        sqlSession.close();
    }
/*添加医生的专业
    医生专业关联表*/
    public void addVetSpecs(Vet_specialityKey vet_specialityKey) throws Exception{
        SqlSession sqlSession = MybatisUtils.getSession();
        sqlSession.insert("com.mapper"
                + ".VetMapper.addVetSpecs",vet_specialityKey);
        sqlSession.commit();
        sqlSession.close();
    }
//多对多查询医生专业信息
    public List<Vet> findvetByVnameAndSname(Vet_specialityKey vet_speciality)throws Exception{
        SqlSession session = MybatisUtils.getSession();
        List<Vet> vets=session.selectList("com.mapper.VetMapper.selectVetWithSpecs",vet_speciality);
        System.out.println(vets);
        session.close();
        return vets;
    }
/*删除医生
    医生表*/
    public void deleteVet(Vet id) throws Exception{
        SqlSession sqlSession = MybatisUtils.getSession();
        int rows = sqlSession.delete("com.mapper"
                + ".VetMapper.deleteVet", id);
        if(rows > 0){
            System.out.println("您成功删除了vet表中的"+rows+"条数据！");
        }else{
            System.out.println("执行删除操作失败！！！");
        }
        // 4.3提交事务
        sqlSession.commit();
        // 5、关闭SqlSession
        sqlSession.close();
    }
/*
    删除医生
    删除医生专业关联表数据*/
    public void deleteVetSpecs(Vet id) throws Exception{
        SqlSession sqlSession = MybatisUtils.getSession();
        int rows2 = sqlSession.delete("com.mapper"
                + ".VetMapper.deleteVetSpecs", id);
        if(rows2 > 0){
            System.out.println("您成功删除了vet_speciality表中的"+rows2+"条数据！");
        }else{
            System.out.println("执行删除操作失败！！！");
        }
        // 4.3提交事务
        sqlSession.commit();
        // 5、关闭SqlSession
        sqlSession.close();
    }
}
